
package com.cheng.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * <日期工具类>
 * 
 * @author 陈强
 * @version 1.0
 * @since ProxyFees1.0
 * @date 2012-05-06
 */
public class DateUtil {

	/**
	 * 获取当前时间字符串<br>
	 * 格式为:yyyyMMddHHmmssSSS
	 * 
	 * @return 当前时间字符串
	 */
	public static String formateDate() {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.CHINESE);

		nowtime = ch.format(new Date());
		return nowtime;
	}

	/**
	 * 获取现在时间
	 * 
	 * @return返回长时间格式 yyyy-MM-dd HH:mm:ss
	 */
	public static Date getNowDate() {
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(currentTime);
		Date converDate = converDate(dateString);
		return converDate;
	}

	/**
	 * 获取日期时间（无毫秒）yyyyMMddHHmmss
	 * 
	 * @return
	 */
	public static String formateDateNoSSS() {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINESE);

		nowtime = ch.format(new Date());
		return nowtime;
	}

	/**
	 * 获取当前时间<br>
	 * 格式化为:yyyy-MM-dd
	 * 
	 * @return yyyy-MM-dd格式字符串
	 */
	public static String formateDateNoTime() {
		String nowTime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd");

		nowTime = ch.format(new Date());

		return nowTime;

	}

	/**
	 * 格式化日期<br>
	 * 格式为:yyyy-MM-dd
	 * 
	 * @param date
	 *            源日期
	 * @return yyyy-MM-dd格式字符串
	 */
	public static String formateDateNoTime(Date date) {

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

		return df.format(date);

	}

	/**
	 * 获取日期时间yyyy-MM-dd HH:mm:ss
	 * 
	 * @return
	 */
	public static String formateDate2() {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);

		nowtime = ch.format(new Date());
		return nowtime;
	}

	/*
	 * public static boolean IsLieDate(String lieDate) { boolean flag = false;
	 * try { Date c = new Date(); if (lieDate != null && !lieDate.equals("")) {
	 * Date lie = getDateBystr(lieDate); if (lie.getTime() < c.getTime()) { flag
	 * = true; } }
	 * 
	 * } catch (Exception e) { e.printStackTrace(); } return flag; }
	 */

	public static Map<String, String> getWeeks(String cur_day) {

		Map<String, String> map = new java.util.Hashtable<String, String>();

		try {
			DateFormat df = DateFormat.getDateInstance();
			Calendar c = Calendar.getInstance();
			c.setTime(df.parse(cur_day));
			int weekDay = c.get(Calendar.DAY_OF_WEEK) == 1 ? 8 : c.get(Calendar.DAY_OF_WEEK);
			c.add(Calendar.DATE, Calendar.MONDAY - weekDay);
			Date start = c.getTime();
			Date end = null;
			map.put("back", dateAdd(start, -1));
			map.put("week0", DateUtil.getStandardDate("yyyy-M-d", start) + "|星期" + DateUtil.getDayOfWeek(start));
			for (int i = 0; i < 6; i++) {
				c.add(Calendar.DATE, 1);
				end = c.getTime();
				map.put("week" + (i + 1),
						DateUtil.getStandardDate("yyyy-M-d", end) + "|星期" + DateUtil.getDayOfWeek(end));
			}

			map.put("proview", dateAdd(end, 1));
			// System.out.println("start=="+DateUtil.getStandardDate(start)+"
			// 星期"+DateUtil.getDayOfWeek(start));
			// System.out.println("end=="+DateUtil.getStandardDate(end)+"
			// 星期"+DateUtil.getDayOfWeek(end));
		} catch (Exception e) {
			e.printStackTrace();
		}

		return map;
	}

	public static Map<String, String> getDays(String cur_day, int m) {
		Map<String, String> map = new java.util.Hashtable<String, String>();
		try {
			DateFormat df = DateFormat.getDateInstance();
			Calendar c = Calendar.getInstance();
			c.setTime(df.parse(cur_day));
			c.add(Calendar.DATE, m);

			int yyyy = c.get(Calendar.YEAR);
			int mm = c.get(Calendar.MONTH);
			int dd = c.get(Calendar.DATE);

			// System.out.println("yyyy=="+yyyy);
			// System.out.println("mm=="+mm);
			// System.out.println("dd=="+dd);

			Date date = c.getTime();

			map.put("date", DateUtil.getStandardDate("yyyy-M-d", date));
			map.put("dateStr", yyyy + "年" + (mm + 1) + "月" + dd + "日 星期" + DateUtil.getDayOfWeek(date));

			map.put("yyyy", String.valueOf(yyyy));
			map.put("mm", String.valueOf(mm));
			map.put("dd", String.valueOf(dd));

			// System.out.println(DateUtil.getStandardDate("yyyy-M-d",date)+"|星期"+DateUtil.getDayOfWeek(date));
		} catch (Exception e) {
			e.printStackTrace();
		}

		// Set s=map.keySet();
		// Iterator i=s.iterator();
		// while(i.hasNext())
		// {
		// String key=(String)i.next();
		// System.out.println(key+"==="+map.get(key));
		// }

		return map;
	}

	public static String getNextHour(String cur_day, int m) {

		String str = "";

		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			Calendar c = Calendar.getInstance();
			c.setTime(df.parse(cur_day));
			c.add(Calendar.HOUR, m); // 传入时间增加1小时
			Date date = c.getTime();

			str = df.format(date);

			str = str.substring(11, str.length());

		} catch (Exception e) {
			e.printStackTrace();
		}

		return str;
	}

	/**
	 * 字符串日期格式化为Date yyyy-MM-dd HH:mm:ss
	 * 
	 * @param strDate
	 * @return
	 */
	/*
	 * public static Date getDateBystr(String strDate) { SimpleDateFormat df =
	 * new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dt = null; try { if
	 * (ValidationUtil.isNotBlank(strDate)) { dt = new Date(); dt =
	 * df.parse(strDate); }
	 * 
	 * } catch (ParseException e) { e.printStackTrace(); } return dt; }
	 */

	/**
	 * 字符串日期格式化为Date yyyy-MM-dd
	 * 
	 * @param strDate
	 * @return
	 */
	public static Date getDateBystr2(String strDate) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date dt = new Date();
		try {
			dt = df.parse(strDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dt;
	}

	/**
	 * 字符串日期格式化为Date yyyyMMdd
	 * 
	 * @param strDate
	 * @return
	 */
	public static Date getDateBystr5(String strDate) {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
		Date dt = new Date();
		try {
			dt = df.parse(strDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dt;
	}

	/**
	 * 获取时间<br>
	 * 格式为:yyyyMMddHHmmss
	 * 
	 * @param strDate
	 *            待格式化日期字符串
	 * @return 日期Date类型
	 */
	public static Date getDateBystr4(String strDate) {
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		Date dt = null;
		try {
			dt = dateFormat.parse(strDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dt;
	}

	/**
	 * 字符串（yyyyMMddHHmmss）日期格式化为Date yyyy-MM-dd HH:mm:ss
	 * 
	 * @param strDate
	 * @return
	 */
	public static Date getDateBystr3(String strDate) {
		if (strDate == null) {
			return null;
		}
		StringBuffer buffer = new StringBuffer();
		if (strDate.length() != 14) {

			buffer.append(strDate.substring(0, 4)).append("-");
			buffer.append(strDate.substring(4, 6)).append("-");
			buffer.append(strDate.substring(6, 8));
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			Date dt = new Date();
			try {
				dt = df.parse(buffer.toString());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return dt;
		} else {

			buffer.append(strDate.substring(0, 4)).append("-");
			buffer.append(strDate.substring(4, 6)).append("-");
			buffer.append(strDate.substring(6, 8)).append(" ");
			buffer.append(strDate.substring(8, 10)).append(":");
			buffer.append(strDate.substring(10, 12)).append(":");
			buffer.append(strDate.substring(12, 14));

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date dt = new Date();
			try {
				dt = df.parse(buffer.toString());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return dt;
		}
	}

	/**
	 * 根据Date格式化为String 返回yyyyMMddHHmmssSSS
	 * 
	 * @param date
	 * @return
	 */
	public static String getStrByDate(Date date) {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.CHINESE);

		nowtime = ch.format(date);
		return nowtime;
	}

	/**
	 * 根据Date格式化为String 返回yyyyMMddHHmmss
	 * 
	 * @param date
	 * @return
	 */
	public static String getStrByDateNoSSS(Date date) {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINESE);

		nowtime = ch.format(date);
		return nowtime;
	}

	public static String dateAdd(Date d, int day) {
		String dateStr = "";
		try {
			java.text.Format forma = new java.text.SimpleDateFormat("yyyy-MM-dd");
			java.util.Calendar Cal = java.util.Calendar.getInstance();
			Cal.setTime(d);
			Cal.add(Calendar.DAY_OF_MONTH, day);

			dateStr = forma.format(Cal.getTime());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dateStr;
	}

	public static Date yearAdd(Date d, int year) {

		try {
			// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd
			// HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.setTime(d);
			c.add(Calendar.YEAR, year); // 传入时间增加N年
			d = c.getTime();
		} catch (Exception e) {

			e.printStackTrace();
		}
		return d;
	}

	public static String dateAdd(String cur_day, int hour) {

		String str = "";
		try {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			Calendar c = Calendar.getInstance();
			c.setTime(df.parse(cur_day));
			c.add(Calendar.HOUR, hour); // 传入时间增加1小时
			Date date = c.getTime();
			str = df.format(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	// 比较时间大小
	public static int timeCompare(String t1, String t2) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c1 = Calendar.getInstance();
		Calendar c2 = Calendar.getInstance();
		try {
			c1.setTime(formatter.parse(t1));
			c2.setTime(formatter.parse(t2));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		int result = c1.compareTo(c2);
		// System.out.println("result=="+result);
		return result;
	}

	public static String getStandardDate(String completeDate) {
		String nowtime = "";
		try {
			SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);

			nowtime = ch.format(ch.parse(completeDate));

		} catch (Exception ex) {
			System.out.println("getStandardDate:" + ex.getMessage());
		}

		return nowtime;
	}

	public static String getStandardDateShort(String completeDate) {
		String nowtime = "";
		try {

			SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);

			nowtime = ch.format(ch.parse(completeDate));
		} catch (Exception ex) {
			System.out.println("getStandardDate:" + ex.getMessage());
		}

		return nowtime;
	}

	public static String getStandardDate(String formatDate, String completeDate) {
		String nowtime = "";
		try {
			SimpleDateFormat ch = new SimpleDateFormat(formatDate, Locale.CHINESE);

			nowtime = ch.format(ch.parse(completeDate));
		} catch (Exception ex) {
			System.out.println("getStandardDate:" + ex.getMessage());
		}

		return nowtime;
	}

	/**
	 * 
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String getStandardDate(Date date) {
		String dateStr = "";
		if (date != null) {
			SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);
			dateStr = ch.format(date);
		}

		return dateStr;
	}

	public static String getStandardDate(String formatDate, Date date) {
		if (null != date) {
			SimpleDateFormat ch = new SimpleDateFormat(formatDate, Locale.CHINESE);
			String dateStr = ch.format(date);
			return dateStr;
		}
		return "";
	}

	public static int getStandardDate(Date date, int type) {
		int year = 0;
		int month = 0;
		int day = 0;
		try {
			java.util.Calendar Cal = java.util.Calendar.getInstance();
			Cal.setTime(date);
			year = Cal.get(Calendar.YEAR);
			month = Cal.get(Calendar.MONTH) + 1;
			day = Cal.get(Calendar.DAY_OF_MONTH);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (type == 1) {
			return year;
		} else if (type == 2) {
			return month;
		} else if (type == 3) {
			return day;
		}

		return 0;

	}

	/**
	 * 获取日期时间字符串yyyyMMddHHmmssSSS
	 * 
	 * @return
	 */
	public static String getDateStr() {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.CHINESE);

		nowtime = ch.format(new Date());
		return nowtime;
	}

	/**
	 * 获取当前日期yyyyMMdd格式
	 * 
	 * @return
	 */
	public static String getDateStrNoSSS() {
		String nowtime = null;

		SimpleDateFormat ch = new SimpleDateFormat("yyyyMMdd", Locale.CHINESE);

		nowtime = ch.format(new Date());
		return nowtime;
	}

	/**
	 * 
	 * @return yyyy-MM-dd
	 */
	public static String getToday() {
		SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
		Date date = new Date();
		return ch.format(date);
	}

	/**
	 * 查询昨天日期
	 * 
	 * @return yyyy-MM-dd
	 */
	public static String getYesterday() {
		SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(new Date());
		cal.add(GregorianCalendar.HOUR, -24);
		Date date = cal.getTime();
		// Date date =new Date(new Date().getYear(),new Date().getMonth(),new
		// Date().getDate()-1);
		return ch.format(date);
	}

	/**
	 * 查询昨天日期
	 * 
	 * @param format
	 *            格式化
	 * @return
	 */
	public static String getYesterday(String format) {
		SimpleDateFormat ch = new SimpleDateFormat(format, Locale.CHINA);

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(new Date());
		cal.add(GregorianCalendar.HOUR, -24);
		Date date = cal.getTime();
		// Date date =new Date(new Date().getYear(),new Date().getMonth(),new
		// Date().getDate()-1);
		return ch.format(date);
	}

	/**
	 * 获取前天日期
	 * 
	 * @return
	 */
	public static String getTheDayBeforeYestoday() {
		Calendar calendar = Calendar.getInstance();// 此时打印它获取的是系统当前时间
		calendar.add(Calendar.DATE, -2); // 得到前天日期
		String theDayBeforeYestoday = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
		return theDayBeforeYestoday;
	}

	public static String getLastMonthEndDate() {

		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(new Date());
		cal.add(GregorianCalendar.MONTH, -1);
		Date date = cal.getTime();

		Calendar now = Calendar.getInstance(Locale.CHINESE);
		now.setTime(date);
		int last = cal.getActualMaximum(Calendar.DATE);

		String time = now.get(Calendar.YEAR) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + last;
		return time;
	}

	public static String getMonthStartDate() {
		Calendar now = Calendar.getInstance(Locale.CHINESE);
		String time = now.get(Calendar.YEAR) + "-" + (now.get(Calendar.MONTH) + 1) + "-1";
		return time;
	}

	public static String getDayOfWeek(Date date) {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		c.setTime(date);
		String dayOfWeekStr = "";
		int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
		switch (dayOfWeek) {
		case 1:
			dayOfWeekStr = "日";
			break;
		case 2:
			dayOfWeekStr = "一";
			break;
		case 3:
			dayOfWeekStr = "二";
			break;
		case 4:
			dayOfWeekStr = "三";
			break;
		case 5:
			dayOfWeekStr = "四";
			break;
		case 6:
			dayOfWeekStr = "五";
			break;
		case 7:
			dayOfWeekStr = "六";
			break;
		}
		return dayOfWeekStr;
	}

	public static int isOverTime(String complainDate, String timeLimit, String completeDate) {
		int i = -1;
		try {
			SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);

			GregorianCalendar cal = new GregorianCalendar();

			Date date_TimeLimit = ch.parse(complainDate);
			Date date_CompleteDate = null;
			Date date_now = new Date();

			cal.setTime(date_TimeLimit);

			if (timeLimit.equals("12Сʱ"))
				cal.add(GregorianCalendar.HOUR, 12);
			if (timeLimit.equals("24Сʱ"))
				cal.add(GregorianCalendar.HOUR, 24);
			if (timeLimit.equals("48Сʱ"))
				cal.add(GregorianCalendar.HOUR, 48);
			if (timeLimit.equals("72Сʱ"))
				cal.add(GregorianCalendar.HOUR, 72);
			if (timeLimit.equals("96Сʱ"))
				cal.add(GregorianCalendar.HOUR, 96);
			if (timeLimit.equals("120Сʱ"))
				cal.add(GregorianCalendar.HOUR, 120);

			date_TimeLimit = cal.getTime();

			if (completeDate != null && !completeDate.equals("")) {

				if (completeDate.indexOf("1900") >= 0) {
					if (date_now.compareTo(date_TimeLimit) >= 0)
						return 1;
				} else {
					date_CompleteDate = ch.parse(completeDate);
					if (date_CompleteDate.compareTo(date_TimeLimit) >= 0)
						i = 1;
				}
			} else {
				if (date_now.compareTo(date_TimeLimit) >= 0)
					return 1;
			}

		} catch (Exception ex) {
			System.out.println(new Date() + " isOverTime:" + ex.getMessage());
		}
		return i;
	}

	public static String getOverTime(String complainDate, String timeLimit) {
		String overTime = "";
		try {
			SimpleDateFormat ch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);

			GregorianCalendar cal = new GregorianCalendar();

			Date date_TimeLimit = ch.parse(complainDate);
			cal.setTime(date_TimeLimit);

			if (timeLimit.equals("12Сʱ"))
				cal.add(GregorianCalendar.HOUR, 12);
			if (timeLimit.equals("24Сʱ"))
				cal.add(GregorianCalendar.HOUR, 24);
			if (timeLimit.equals("48Сʱ"))
				cal.add(GregorianCalendar.HOUR, 48);
			if (timeLimit.equals("72Сʱ"))
				cal.add(GregorianCalendar.HOUR, 72);
			if (timeLimit.equals("96Сʱ"))
				cal.add(GregorianCalendar.HOUR, 96);
			if (timeLimit.equals("120Сʱ"))
				cal.add(GregorianCalendar.HOUR, 120);

			date_TimeLimit = cal.getTime();
			overTime = ch.format(date_TimeLimit);

		} catch (Exception ex) {
			System.out.println(new Date() + " getOverTime:" + ex.getMessage());
		}
		return overTime;
	}

	public static boolean isInteger(String str) {
		if (str == null)
			return false;
		Pattern pattern = Pattern.compile("[0-9]+");
		return pattern.matcher(str).matches();
	}

	public static String dateAddReturnStr(Date d, int hour) {
		String dateStr = "";
		try {
			java.text.Format forma = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			java.util.Calendar Cal = java.util.Calendar.getInstance(Locale.CHINESE);
			Cal.setTime(d);
			Cal.add(java.util.Calendar.HOUR_OF_DAY, hour);
			dateStr = forma.format(Cal.getTime());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dateStr;
	}

	public static String diffDateStr(Date begDate, Date endDate) {
		String result = "";

		try {
			Date currentTime = endDate;
			endDate.toString();
			if (currentTime.getTime() > begDate.getTime()) {
				long interval = (currentTime.getTime() - begDate.getTime()) / 1000;// 秒
				long day = interval / (24 * 3600);// 天
				long hour = interval % (24 * 3600) / 3600;// 小时
				long minute = interval % 3600 / 60;// 分钟
				String dayResult = "";
				if (day > 0) {
					dayResult = day + "天";
				}

				String hourResult = "";
				if (hour > 0) {
					hourResult = hour + "小时";
				}

				result = dayResult + hourResult + minute + "分";
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return result;
	}

	public static Date converDate(String dateStr) {

		Date d1 = null;

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			d1 = sdf.parse(dateStr);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return d1;
	}

	public static Date converDate(String dateStr, String formatte) {

		Date d1 = null;

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(formatte);
			d1 = sdf.parse(dateStr);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return d1;
	}

	public static int diffMin(Date begDate, Date endDate) {
		int min = 0;

		try {

			Date currentTime = endDate;

			if (currentTime.getTime() > begDate.getTime()) {
				long interval = (currentTime.getTime() - begDate.getTime()) / 1000;// 秒

				min = (int) interval / 60;// 分钟
				// if((interval %60)>0){
				// min+=1;
				// }
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return min;
	}

	/** **获取当前年、季度、月、星期、日、小时开始日期时间和结束日期时间 ========>>>>>>>>>开始*** */

	/**
	 * 获得本周的第一天，即周日
	 * 
	 * @return
	 */
	public static Date getCurrentWeekDayStartTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {

			int weekday = c.get(Calendar.DAY_OF_WEEK) - 1;
			c.add(Calendar.DATE, -weekday);
			c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c.getTime();
	}

	/**
	 * 获得本周的最后一天，即本周六
	 * 
	 * @return
	 */
	public static Date getCurrentWeekDayEndTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {

			int weekday = c.get(Calendar.DAY_OF_WEEK);
			c.add(Calendar.DATE, 7 - weekday);
			c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c.getTime();
	}

	/**
	 * 获得本天的开始时间，即2012-01-01 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentDayStartTime() {
		Date now = new Date();
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			now = shortSdf.parse(shortSdf.format(now));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得指定日期当天的开始时间，即2012-01-01 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentDayStartTime(Date now) {
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			now = shortSdf.parse(shortSdf.format(now) + " 00:00:00");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得本天的结束时间，即2012-01-01 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentDayEndTime() {
		Date now = new Date();
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			now = longSdf.parse(shortSdf.format(now) + " 23:59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得指定日期当天的结束时间，即2012-01-01 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentDayEndTime(Date now) {
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			now = longSdf.parse(shortSdf.format(now) + " 23:59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得本小时的开始时间，即2012-01-01 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentHourStartTime() {
		Date now = new Date();
		try {
			now = new SimpleDateFormat().parse(new SimpleDateFormat().format(now));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得本小时的结束时间，即2012-01-01 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentHourEndTime() {
		Date now = new Date();
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			now = longSdf.parse(new SimpleDateFormat().format(now) + ":59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得本月的开始时间，即2012-01-01 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentMonthStartTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			c.set(Calendar.DATE, 1);
			now = shortSdf.parse(shortSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 获得本月的开始时间，即2012-01-01 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentMonthStartTime(Date date) {
		Calendar c = Calendar.getInstance();
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			// c.set( Calendar.DATE, 1 );
			c.setTime(date);
			c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
			now = shortSdf.parse(shortSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 当前月的结束时间，即2012-01-31 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentMonthEndTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			c.set(Calendar.DATE, 1);
			c.add(Calendar.MONTH, 1);
			c.add(Calendar.DATE, -1);
			now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	public static Date getCurrentMonthEndTime(Date date) {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			// c.set( Calendar.DATE, 1 );
			c.setTime(date);
			// c.add( Calendar.MONTH, 1 );
			// c.add( Calendar.DATE, -1 );
			c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
			now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 当前年的开始时间，即2012-01-01 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentYearStartTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			c.set(Calendar.MONTH, 0);
			c.set(Calendar.DATE, 1);
			now = shortSdf.parse(shortSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 当前年的结束时间，即2012-12-31 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentYearEndTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		Date now = null;
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			c.set(Calendar.MONTH, 11);
			c.set(Calendar.DATE, 31);
			now = shortSdf.parse(shortSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 当前季度的开始时间，即2012-01-1 00:00:00
	 * 
	 * @return
	 */
	public static Date getCurrentQuarterStartTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		Date now = null;
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			if (currentMonth >= 1 && currentMonth <= 3)
				c.set(Calendar.MONTH, 0);
			else if (currentMonth >= 4 && currentMonth <= 6)
				c.set(Calendar.MONTH, 3);
			else if (currentMonth >= 7 && currentMonth <= 9)
				c.set(Calendar.MONTH, 4);
			else if (currentMonth >= 10 && currentMonth <= 12)
				c.set(Calendar.MONTH, 9);
			c.set(Calendar.DATE, 1);
			now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/**
	 * 当前季度的结束时间，即2012-03-31 23:59:59
	 * 
	 * @return
	 */
	public static Date getCurrentQuarterEndTime() {
		Calendar c = Calendar.getInstance(Locale.CHINESE);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		Date now = null;
		SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			if (currentMonth >= 1 && currentMonth <= 3) {
				c.set(Calendar.MONTH, 2);
				c.set(Calendar.DATE, 31);
			} else if (currentMonth >= 4 && currentMonth <= 6) {
				c.set(Calendar.MONTH, 5);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 7 && currentMonth <= 9) {
				c.set(Calendar.MONTH, 8);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 10 && currentMonth <= 12) {
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			}
			now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return now;
	}

	/** **获取当前年、季度、月、星期、日、小时开始日期时间和结束日期时间 ========>>>>>>>>>結束*** */

}
